package com.example.lenovo.appstore.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.SearchView;

import com.example.lenovo.appstore.R;
import com.example.lenovo.appstore.adapter.CartUpdateListAdapter;
import com.example.lenovo.appstore.adapter.HomeAppListAdapter;
import com.example.lenovo.appstore.utils.StatusBarUtil;
import com.example.lenovo.model.CategoryListModel;

import java.util.ArrayList;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 项目名称：AppStore
 *
 * @Author 郭迎辉
 * Create by 9:38 on 2019/3/20.
 * Describe:
 */
public class CartFragment extends Fragment {
    public static CartFragment instance;
    @Bind(R.id.search)
    SearchView searchView;
    @Bind(R.id.list)
    RecyclerView list;
    private Context context;
    private View view;
    CartUpdateListAdapter adapter;

    public static CartFragment getInstance() {
        if (null == instance) {
            instance = new CartFragment();
        }
        return instance;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        // 隐藏软键盘
        getActivity().getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        StatusBarUtil.setStatusBarLightMode(getActivity().getWindow());
        ArrayList<CategoryListModel.CategoryList> datas = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            datas.add(new CategoryListModel.CategoryList());
        }
        adapter = new CartUpdateListAdapter(getActivity(), datas);
        list.setLayoutManager(new LinearLayoutManager(getActivity()));
        list.setAdapter(adapter);
        list.setHasFixedSize(true);
        list.setNestedScrollingEnabled(false);
        adapter.notifyDataSetChanged();
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context = context;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (null == view) {
            view = inflater.inflate(R.layout.fragment_paihang, container, false);
            ButterKnife.bind(this, view);
//            initView();
        } else {
            if (null != view.getParent()) {
                ((ViewGroup) view.getParent()).removeAllViews();
            }

        }
        instance = this;
        return view;
    }


}
